package syyrjx.Filter;

import javax.servlet.*;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class LogFilter implements Filter {
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest)servletRequest;
        if(request.getRequestURI().indexOf("log") == -1) {
            if (request.getSession(false) == null) {
                HttpServletResponse response = (HttpServletResponse) servletResponse;
                response.sendRedirect("log.html");
                return;
            }
        }
        filterChain.doFilter(servletRequest,servletResponse);
    }
}
